package org.vy.dal.dao.lookup;

import java.util.List;

import org.vy.dal.QueryManager;

public class VyLookupPatrikaPeriodCostDAO {
	private static final String FIND_BY_PK = "SELECT * FROM <TABLE> WHERE PATRIKA_PERIOD_ID = m_PatrikaPeriodId";
	private static final String FIND_UNIQUE_PERIOD = "SELECT DISTINCT PERIOD_NAME, PERIOD_MONTH FROM <TABLE> WHERE IS_ACTIVE = TRUE";
	private static final String UPDATE = "UPDATE <TABLE> SET PATRIKA_NAME = m_PatrikaName, PER_COPY_AMOUNT = m_PerCopyAmount,EFFECTIVE_DATE=m_EffectiveDate, LAST_UPDATED_BY = m_LastUpdatedBy, LAST_UPDATED_ON = m_LastUpdatedOn WHERE PATRIKA_ID = m_PatrikaId";
	private static final String INSERT = "INSERT INTO <TABLE> (PATRIKA_ID,PATRIKA_NAME,PATRIKA_COST,EFFECTIVE_DATE,WEEK_OFFSET_INDEX,IS_DELETED,LAST_UPDATED_BY,LAST_UPDATED_ON)VALUES(m_PatrikaId,m_PatrikaName,m_PatrikaCost,m_EffectiveDate,m_WeekOffsetIndex,m_IsDeleted,m_LastUpdatedBy,m_LastUpdatedOn)";
	private static final String DELETE = "DELETE FROM <TABLE> WHERE PATRIKA_CODE = m_PatrikaCode";

	public static VyLookupPatrikaPeriodCostDO findByPK(Integer key) throws Exception {
		VyLookupPatrikaPeriodCostDO dto = new VyLookupPatrikaPeriodCostDO();
		dto.setPatrikaId(key);
		dto = (VyLookupPatrikaPeriodCostDO) QueryManager.executeQuery(dto, FIND_BY_PK);
		return dto;
	}
	
	@SuppressWarnings("unchecked")
	public static List<VyLookupPatrikaPeriodCostDO> findUniquePeriod() throws Exception {
		VyLookupPatrikaPeriodCostDO dto = new VyLookupPatrikaPeriodCostDO();
//		dto.setEffectiveDate(new Date());
		return (List<VyLookupPatrikaPeriodCostDO>) QueryManager.executeListQuery(dto, FIND_UNIQUE_PERIOD);
	}

	public static VyLookupPatrikaPeriodCostDO insert(VyLookupPatrikaPeriodCostDO dto) throws Exception {
		dto.setPatrikaId(0);
		dto = (VyLookupPatrikaPeriodCostDO) QueryManager.executeInsert(dto, INSERT);
		return dto;
	}

	public static VyLookupPatrikaPeriodCostDO update(VyLookupPatrikaPeriodCostDO dto) throws Exception {
		int i = QueryManager.executeUpdate(dto, UPDATE);
		if (i > 0)
			return dto;
		else
			return null;
	}

	public static VyLookupPatrikaPeriodCostDO delete(Integer key) throws Exception {
		VyLookupPatrikaPeriodCostDO dto = new VyLookupPatrikaPeriodCostDO();
		dto.setPatrikaId(key);
		boolean i = QueryManager.executeDelete(dto, DELETE);
		if (i == true)
			return dto;
		else
			return null;
	}
}
